﻿package com.toncen.samepms.system.domain;

import java.util.ArrayList;
import java.util.List;

import com.toncen.samepms.common.AbstractDomain;
import com.toncen.samepms.common.IPropertyUniqueble;
import com.toncen.samepms.common.ITreeable;
import com.toncen.samepms.common.Unique;
import com.sky.common.string.StringUtils;

/**
 * 描述：模块表SYSTEM_MODULE的domain文件
 * 
 * @author tch
 */
public class Module extends AbstractDomain implements ITreeable, IPropertyUniqueble {
	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1331283566457L;

	/**
	 * 桌面统计过滤类型替换符开始符号
	 */
	public static final String SCOPE_PLACEHOLDER_START = "{";

	/**
	 * 桌面统计过滤类型替换符结束符号
	 */
	public static final String SCOPE_PLACEHOLDER_END = "}";

	/**
	 * 桌面统计过滤类型替换符默认类型
	 */
	public static final String SCOPE_PLACEHOLDER_DEFAULT = SCOPE_PLACEHOLDER_START + "scope" + SCOPE_PLACEHOLDER_END;
	/**
	 * 标签起始标记
	 */
	public static final String OGNL_START_TAG = "%{";

	/**
	 * 标签结束标记
	 */
	public static final String OGNL_END_TAG = "}%";
	/**
	 * 上级模块
	 */
	@Unique(column = "PARENT_ID", title = "上级模块", complexField = true)
	private com.toncen.samepms.system.domain.Module parent;

	/**
	 * 名称
	 */
	@Unique(column = "NAME", title = "名称")
	private String name;

	/**
	 * 图标
	 */
	private String icon;

	/**
	 * 链接地址
	 */
	private String linkUrl;

	/**
	 * 顺序
	 */
	private int sequence = 10;

	/**
	 * 桌面统计组
	 */
	private int desktopGroup;

	/**
	 * 桌面统计名称
	 */
	private String desktopName;

	/**
	 * 桌面统计过滤类型
	 */
	private String desktopFilterType;

	/**
	 * 桌面统计过滤类型数组(不持久化)
	 */
	private String[] desktopFilterTypes;

	/**
	 * 桌面统计查询字段
	 */
	private String desktopQueryColumn;

	/**
	 * 桌面统计查询值
	 */
	private String desktopQueryValue;

	/**
	 * 桌面统计动态字段
	 */
	private String desktopDynamicColumn;

	/**
	 * 桌面统计动态值
	 */
	private String desktopDynamicValue;

	/**
	 * 桌面统计顺序
	 */
	private int desktopSequence = 10;

	/**
	 * 桌面统计Fisher
	 */
	private String desktopFishergrid;

	private List<Module> childs = new ArrayList<Module>();

	public Module() {
		super();
	}

	/**
	 * @return the parent
	 */
	public com.toncen.samepms.system.domain.Module getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(com.toncen.samepms.system.domain.Module parent) {
		this.parent = parent;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the icon
	 */
	public String getIcon() {
		return icon;
	}

	/**
	 * @param icon
	 *            the icon to set
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}

	/**
	 * @return the linkUrl
	 */
	public String getLinkUrl() {
		return linkUrl;
	}

	/**
	 * @param linkUrl
	 *            the linkUrl to set
	 */
	public void setLinkUrl(String linkUrl) {
		this.linkUrl = linkUrl;
	}

	/**
	 * @return the sequence
	 */
	public int getSequence() {
		return sequence;
	}

	/**
	 * @param sequence
	 *            the sequence to set
	 */
	public void setSequence(int sequence) {
		this.sequence = sequence;
	}

	/**
	 * @return the childs
	 */
	public List<Module> getChilds() {
		return childs;
	}

	/**
	 * @param childs
	 *            the childs to set
	 */
	public void setChilds(List<Module> childs) {
		this.childs = childs;
	}

	/**
	 * @return the desktopDynamicColumn
	 */
	public String getDesktopDynamicColumn() {
		return desktopDynamicColumn;
	}

	/**
	 * @param desktopDynamicColumn
	 *            the desktopDynamicColumn to set
	 */
	public void setDesktopDynamicColumn(String desktopDynamicColumn) {
		this.desktopDynamicColumn = desktopDynamicColumn;
	}

	/**
	 * @return the desktopDynamicValue
	 */
	public String getDesktopDynamicValue() {
		return desktopDynamicValue;
	}

	/**
	 * @param desktopDynamicValue
	 *            the desktopDynamicValue to set
	 */
	public void setDesktopDynamicValue(String desktopDynamicValue) {
		this.desktopDynamicValue = desktopDynamicValue;
	}

	/**
	 * @return the desktopFilterType
	 */
	public String getDesktopFilterType() {
		return desktopFilterType;
	}

	/**
	 * @param desktopFilterType
	 *            the desktopFilterType to set
	 */
	public void setDesktopFilterType(String desktopFilterType) {
		this.desktopFilterType = desktopFilterType;
		if (!StringUtils.isEmpty(this.desktopFilterType)) {// 英文逗号分割的字符串转换为整数数组
			String[] filterTypes = this.desktopFilterType.split(",",-1);
			String[] filters = new String[filterTypes.length];
			for (int i = 0; i < filterTypes.length; i++) {
				if (!StringUtils.isEmpty(filterTypes[i])) {
					filters[i] = filterTypes[i];
				}
			}
			this.desktopFilterTypes = filters;
		}
	}

	/**
	 * @return the desktopFilterTypes
	 */
	public String[] getDesktopFilterTypes() {
		return desktopFilterTypes;
	}

	/**
	 * @param desktopFilterTypes
	 *            the desktopFilterTypes to set
	 */
	public void setDesktopFilterTypes(String[] desktopFilterTypes) {
		this.desktopFilterTypes = desktopFilterTypes;
		if (this.desktopFilterTypes != null) {// 整数数组转换为英文逗号分割的字符串
			StringBuffer desktopFilterType = new StringBuffer();
			for (String filter : this.desktopFilterTypes) {
				desktopFilterType.append(",");
				desktopFilterType.append(filter);
			}
			this.desktopFilterType = desktopFilterType.toString().replaceFirst(",", "");
		}
	}

	/**
	 * @return the desktopFishergrid
	 */
	public String getDesktopFishergrid() {
		return desktopFishergrid;
	}

	/**
	 * @param desktopFishergrid
	 *            the desktopFishergrid to set
	 */
	public void setDesktopFishergrid(String desktopFishergrid) {
		this.desktopFishergrid = desktopFishergrid;
	}

	/**
	 * @return the desktopGroup
	 */
	public int getDesktopGroup() {
		return desktopGroup;
	}

	/**
	 * @param desktopGroup
	 *            the desktopGroup to set
	 */
	public void setDesktopGroup(int desktopGroup) {
		this.desktopGroup = desktopGroup;
	}

	/**
	 * @return the desktopName
	 */
	public String getDesktopName() {
		return desktopName;
	}

	/**
	 * @param desktopName
	 *            the desktopName to set
	 */
	public void setDesktopName(String desktopName) {
		this.desktopName = desktopName;
	}

	/**
	 * @return the desktopQueryColumn
	 */
	public String getDesktopQueryColumn() {
		return desktopQueryColumn;
	}

	/**
	 * @param desktopQueryColumn
	 *            the desktopQueryColumn to set
	 */
	public void setDesktopQueryColumn(String desktopQueryColumn) {
		this.desktopQueryColumn = desktopQueryColumn;
	}

	/**
	 * @return the desktopQueryValue
	 */
	public String getDesktopQueryValue() {
		return desktopQueryValue;
	}

	/**
	 * @param desktopQueryValue
	 *            the desktopQueryValue to set
	 */
	public void setDesktopQueryValue(String desktopQueryValue) {
		this.desktopQueryValue = desktopQueryValue;
	}

	/**
	 * @return the desktopSequence
	 */
	public int getDesktopSequence() {
		return desktopSequence;
	}

	/**
	 * @param desktopSequence
	 *            the desktopSequence to set
	 */
	public void setDesktopSequence(int desktopSequence) {
		this.desktopSequence = desktopSequence;
	}

	/**
	 * 获取当前模块全部级联下级模块(包括自己)
	 * 
	 * @return
	 */
	public List<Module> getAllChilds() {
		List<Module> allchilds = new ArrayList<Module>();
		allchilds.add(this);
		for (Module child : getChilds()) {
			child.setParent(this);
			allchilds.addAll(child.getAllChilds());
		}
		return allchilds;
	}

	/**
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<ITreeable> getTreeChild() throws Exception {
		return (List) this.getChilds();
	}

	/**
	 * @return
	 * @throws Exception
	 */
	public String getTreeId() throws Exception {
		return String.valueOf(this.getId());
	}

	/**
	 * @return
	 * @throws Exception
	 */
	public String getTreeText() throws Exception {
		return this.getName();
	}

	public String getPrimaryName() {
		// TODO Auto-generated method stub
		return "ID";
	}

	public String getTableName() {
		// TODO Auto-generated method stub
		return "SYSTEM_MODULE";
	}

}
